#include "../h/area.h"

area::area( int width_in, int height_in, area_alg algorithm )
{
    height = height_in;
    width = width_in;
    data = new char*[height];
    for(int i=0;i<height;i++)
        data[i] = new char[width];
    switch(algorithm){
        case walk:
            int sX,sY,eX,eY;
            for(sX=0;sX<width;sX++)
                for(sY=0;sY<height;sY++)
                    data[sX][sY] = 0x23; // #
            sX = (int) (rand()%width); sY = (int) (rand()%height);
            eX = (int) (rand()%width); eY = (int) (rand()%height);
            data[sX][sY] = 0xEF; // upside down U
            while(sX!=eX&&sY!=eY){
                RAND_MOVE:
                int direction = rand()%4;
                if(direction==0&&sX!=0)
                    sX--;
                else if(direction==1&&sX<(width-1))
                    sX++;
                else if(direction==2&&sY!=0)
                    sY--;
                else if(direction==3&&sY<(height-1))
                    sY++;
                else
                    goto RAND_MOVE;
                data[sX][sY] = 0xBB; // Dot
            }
            data[eX][eY] = 0x4F; // Door
            break;
    }
}

area::~area()
{
    for(int i=0;i<height;i++)
        delete [] data[i];
    delete [] data;
}

char area::get_tile( int id )
{
    return data[id/height][id%width];
}

char area::get_tile( int w, int h)
{
    return data[w][h];
}

int area::num_ids()
{
    return (height * width);
}


